home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
conver1a
/
clscolor.cls
Wrap
Text File
|
1999-09-08
|
2KB
|
81 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsColor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public Sub Get_RGB(vl As Long, cl() As Byte)
Dim HexColor As String
HexColor = StrReverse(BinToHEX(DecToBin(vl)))
cl(0) = HexToDec(Mid(HexColor, 1, 2))
cl(1) = HexToDec(Mid(HexColor, 3, 2))
cl(2) = HexToDec(Mid(HexColor, 5, 2))
End Sub
Private Function DecToBin(intNumber As Long) As String
Dim strBin As String
Dim intTemp As Long
Dim dblBin As Double
strBin = 0
While intNumber > 0
strBin = strBin & intNumber Mod 2
intNumber = (intNumber / 2) - 0.1
Wend
DecToBin = Format(StrReverse(strBin), "000000000000000000000000")
End Function
Private Function BinToHEX(binNum As String) As String
Dim hexNumbers(1 To 6) As String * 1
Dim i%, tmp As Byte, tmp2
For i = 1 To 24 Step 4
tmp2 = Mid(binNum, i, 4) '
tmp = Mid(tmp2, 1, 1) * 8 + Mid(tmp2, 2, 1) * 4 + Mid(tmp2, 3, 1) * 2 + Mid(tmp2, 4, 1) * 1 'GetDec()
BinToHEX = BinToHEX & Hex(tmp)
Next
End Function
Private Function HexToDec(Expression As String) As Byte
Dim i As Byte
Dim vl As String
For i = 1 To 2
Select Case Mid(Expression, i, 1)
Case "0": vl = vl & "0000"
Case "1": vl = vl & "0001"
Case "2": vl = vl & "0010"
Case "3": vl = vl & "0011"
Case "4": vl = vl & "0100"
Case "5": vl = vl & "0101"
Case "6": vl = vl & "0110"
Case "7": vl = vl & "0111"
Case "8": vl = vl & "1000"
Case "9": vl = vl & "1001"
Case "A": vl = vl & "1010"
Case "B": vl = vl & "1011"
Case "C": vl = vl & "1100"
Case "D": vl = vl & "1101"
Case "E": vl = vl & "1110"
Case "F": vl = vl & "1111"
End Select
Next
HexToDec = 0
For i = 1 To 8
If Mid(vl, i, 1) = 1 Then HexToDec = HexToDec + 2 ^ (i - 1)
Next
End Function